package ClientFront.Net;

import ClientFront.MyUtils;

import java.net.InetAddress;
import java.net.Socket;

public class ConnectionInfo {

    InetAddress myAddress;
    InetAddress serverAddress;
    int myPort;
    int serverPort;
    public ConnectionInfo(){
        try{
            setLocalIPAddress(InetAddress.getLocalHost().getHostAddress());
        }catch (Exception e){e.printStackTrace();}
        serverPort = 9999;
    }

    public void setLocalIPAddress(String localIPAddress) {
        if(!MyUtils.isValidIPv4Address(localIPAddress)){
            return;
        }
        try{
            myAddress = InetAddress.getByName(localIPAddress);
        }catch (Exception e){}
    }
    public void setServerIpAddress(String serverIpAddress) {
        if(!MyUtils.isValidIPv4Address(serverIpAddress)){
            return;
        }
        try{
            serverAddress = InetAddress.getByName(serverIpAddress);
        }catch (Exception e){}
    }
    public void setMyPort(int myPort) {
        if(MyUtils.isValidPort(myPort)) {
            this.myPort = myPort;
        }
    }
    public void setServerPort(int serverPort) {
        if(MyUtils.isValidPort(serverPort)){
            this.serverPort = serverPort;
        }
    }

    public InetAddress getMyAddress() {
        return myAddress;
    }
    public InetAddress getServerAddress() {
        return serverAddress;
    }
    public int getMyPort() {
        return myPort;
    }
    public int getServerPort() {
        return serverPort;
    }
}